<template>
	<view>
		<view class="m-search">
			<image src="@/static/shop/icon-search.png" mode=""></image>
			<input type="text" @confirm="confirmFun" v-model="keyword" :focus="true" placeholder="输入关键字搜索" placeholder-style="color:#ADAAA5;font-size:24rpx;">
		</view>
		
		<view class="m-h3">
			<text>热门搜索</text>
		</view>
		<view class="m-list">
			<view class="m-item" v-for="(item,index) in goodsList" :key="index" @click="to_link('/pages2/shop-detail/shop-detail?id='+item.inventoryId)">
				<text>{{item.title}}</text>
			</view>
		</view>
		<block v-if="searchList.length > 0">
			<view class="m-h3">
				<text>搜索历史</text>
				<view class="m-del" @click="clearSearchFun">
					<image src="../static/shop/shop-del.png" mode=""></image>
				</view>
			</view>
			<view class="m-list">
				<view class="m-item" v-for="(item,index) in searchList" :key="index" @click="to_link('/pages2/shop-search-list/shop-search-list?keyword='+item)">
					<text>{{item}}</text>
				</view>
			</view>
		</block>
	</view>
</template>

<script>
	import {history_arr} from "@/common/function/tools.js"
	export default {
		data() {
			return {
				goodsList:[],
				searchList:[],
				keyword:''
			}
		},
		onLoad() {
			this.getGoodsFun()
			this.searchList = history_arr()
		},
		methods: {
			getGoodsFun(){
				this.$http.getJson('product_plist',{page:1,pagenum:10}).then(res=>{
					if(res.code == 1){
						let list = res.data || []
						this.goodsList = list
					}
				})
			},
			confirmFun(){
				if(this.$u.test.empty(this.keyword)){
					return this.msg('请输入关键词')
				}
				this.searchList = history_arr('push',this.keyword)
				this.to_link('/pages2/shop-search-list/shop-search-list?keyword='+this.keyword)
			},
			clearSearchFun(){
				history_arr('clear')
				this.searchList = []
			},
		}
	}
</script>

<style lang="scss">
.m-search{
	display: flex;
	align-items: center;
	width: 710rpx;
	height: 60rpx;
	background: #F6F6F6;
	border-radius: 34rpx 34rpx 34rpx 34rpx;
	margin-left: 20rpx;
	margin-top: 20rpx;
	padding: 0 30rpx;
	image{
		width: 30rpx;
		height: 30rpx;
		margin-right: 20rpx;
	}
	input{
		flex: 1;
		height: 100%;
		font-size: 26rpx;
		color: #000;
	}
}

.m-h3{
	display: flex;
	align-items: center;
	justify-content: space-between;
	font-size: 32rpx;
	color: #34302D;
	font-weight: 600;
	padding: 40rpx 20rpx 30rpx;
	.m-del{
		width: 30rpx;
		height: 30rpx;
		image{
			width: 100%;
			height: 100%;
		}
	}
}
.m-list{
	display: flex;
	flex-wrap: wrap;
	margin-left: 20rpx;
	.m-item{
		display: flex;
		justify-content: center;
		align-items: center;
		min-width: 120rpx;
		height: 60rpx;
		background: #F6F6F6;
		border-radius: 12rpx 12rpx 12rpx 12rpx;
		padding: 0 20rpx;
		font-size: 24rpx;
		color: #75706A;
		margin-right: 20rpx;
		margin-bottom: 20rpx;
	}
}
</style>
